package cn.wp.ewallet.wallet.service.impl;

import cn.wp.common.core.authentication.AuthenticationContext;
import cn.wp.common.core.id.Id;
import cn.wp.common.core.util.BeanUtil;
import cn.wp.ewallet.wallet.dao.UserWalletRelDao;
import cn.wp.ewallet.wallet.model.dto.UserWalletRelDto;
import cn.wp.ewallet.wallet.model.entity.UserWalletRelDo;
import cn.wp.ewallet.wallet.service.UserWalletRelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * 用户和钱包关系-业务逻辑层实现
 * Created by zhangyongli on 2020/01/10
 */
@Service
public class UserWalletRelServiceImpl implements UserWalletRelService {

    @Autowired
    private UserWalletRelDao userWalletRelDao;

    @Autowired
    private AuthenticationContext authenticationContext;

    @Override
    public void saveUserWalletRel(String userId, String address) {
        UserWalletRelDo userWalletRelDo = new UserWalletRelDo();
        userWalletRelDo.setUserWalletId(Id.gen());
        userWalletRelDo.setUserId(userId);
        userWalletRelDo.setWalletAddress(address);
        userWalletRelDo.setCreateDate(new Date());
        userWalletRelDao.insertUserWalletRel(userWalletRelDo);
    }

    @Override
    public UserWalletRelDto getUserWalletRel() {
       String userId = authenticationContext.currentUser().getId();
        return BeanUtil.copyProperties(userWalletRelDao.selectUserWalletRel(userId), UserWalletRelDto.class);
    }


}